package com.haha.mylife;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.ab.view.sliding.*;
public class WelcomeActivity extends Activity {

	@Bind(R.id.slidingPlayView) 
	AbSlidingPlayView slidingPlayView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		SharedPreferences sp=getSharedPreferences("app.cfg", MODE_PRIVATE);
		boolean isFirst=sp.getBoolean("isFirst", true);
		if(isFirst==false){
			startActivity(new Intent(
					WelcomeActivity.this,
					Welcome2Activity.class));
			finish();
		}
		
		setContentView(R.layout.activity_welcome);
		ButterKnife.bind(this);
		
		
		slidingPlayView.addView(createView(R.drawable.pic1,false));
		slidingPlayView.addView(createView(R.drawable.pic2,false));
		slidingPlayView.addView(createView(R.drawable.pic3,false));
		slidingPlayView.addView(createView(R.drawable.pic4,false));
		slidingPlayView.addView(createView(R.drawable.pic5,true));
	
		slidingPlayView.setNavImageHeight(10);
		slidingPlayView.setNavImageWidth(10);
		slidingPlayView.setNavHorizontalGravity(1);
		slidingPlayView.setNavPageResources(R.drawable.play_display,
					R.drawable.play_hide);
	
	}
	
	View createView(int imgid,boolean isLast){
		View v=LayoutInflater.from(this)
				.inflate(R.layout.welcome_item, null);
		ViewHolder vh=new ViewHolder(v);
		vh.imageView.setImageResource(imgid);
		if(isLast){
			vh.button1.setVisibility(View.INVISIBLE);
		}else{
			vh.button2.setVisibility(View.INVISIBLE);
		}
		return v;
	}
	
	class ViewHolder{
		@Bind(R.id.imageView1) ImageView imageView;
		@Bind(R.id.button1) Button button1;
		@Bind(R.id.button2) Button button2;	
		public ViewHolder(View v) {
			ButterKnife.bind(this,v);
		}
		
		@OnClick({R.id.button1,R.id.button2}) 
		void btn1Click(){
			SharedPreferences sp=
					getSharedPreferences("app.cfg",MODE_PRIVATE);
			sp.edit().putBoolean("isFirst", false)
			.commit();			
			startActivity(new Intent(
					WelcomeActivity.this,
					Welcome2Activity.class));
			finish();
		}
	}

	
}
